package main

import (
	"fmt"
	"math/rand"
	"time"
)

//随机初始化两个8*5的矩阵，求两个矩阵的和
func matrixAdd() [8][5]int {
	var a = [8][5]int{}
	var b = [8][5]int{}
	var sum = [8][5]int{}
	for i := 0; i < 8; i++ {
		for j := 0; j < 5; j++ {
			rand.Seed(time.Now().UnixMilli())
			a[i][j] = rand.Intn(100 + i*j)
			b[i][j] = rand.Intn(100 + i*j)
			sum[i][j] = a[i][j] + b[i][j]
		}
	}
	fmt.Println(a)
	fmt.Println(b)
	return sum
}

//给定月份，判断属于哪个季节。分别用if个switch实现
func judgeSeason(month int) string {
	if month >= 3 && month <= 5 {
		return "春季"
	} else if month >= 6 && month <= 8 {
		return "夏季"
	} else if month >= 9 && month <= 11 {
		return "秋季"
	} else {
		return "冬季"
	}
}

func judgeSeasonSwitch(month int) string {
	season := ""
	switch month {
	case 2:
	case 3:
	case 4:
		season = "春季"
	case 5:
	case 6:
	case 7:
		season = "夏季"
	case 8:
	case 9:
	case 10:
		season = "秋季"
	case 11:
	case 12:
	case 1:
		season = "冬季"
	default:
		season = "请输入1-12之间的月份"
	}
	return season
}

//创建一个student结构体，包含姓名和语数外三门课的成绩。
type student struct {
	name    string
	chinese float32
	math    float32
	english float32
}

//用一个slice容纳一个班的同学，求每位同学的平均分和整个班三门课的平均分，全班同学平均分低于60的有几位
func getStuAve(students *[]student) []float32 {
	var aves []float32 = []float32{}
	for _, ss := range *students {
		aves = append(aves, (ss.chinese+ss.math+ss.english)/3)
	}
	return aves
}

func getSubAve(students *[]student) []float32 {
	aves := []float32{}
	var sumChinese float32 = 0
	var sumMath float32 = 0
	var sumEng float32 = 0
	var nums int = 0

	for index, ss := range *students {
		sumChinese += ss.chinese
		sumMath += ss.math
		sumEng += ss.english
		nums = index + 1
	}
	aves = append(aves, sumChinese/float32(nums), sumMath/float32(nums), sumEng/float32(nums))
	return aves
}

func getBelow(scores *[]float32) int {
	nums := 0
	for _, score := range *scores {
		if score < 60 {
			nums++
		}
	}
	return nums
}

func main() {
	fmt.Println(matrixAdd())
	fmt.Println(judgeSeason(9))
	fmt.Println(judgeSeasonSwitch(4))
	students := make([]student, 5)
	students[0] = student{name: "zhangsan", chinese: 90.0, math: 50, english: 68}
	students[1] = student{name: "lisi", chinese: 79.0, math: 80, english: 84}
	students[2] = student{name: "wangwu", chinese: 60.0, math: 63, english: 50}
	students[3] = student{name: "zhaoliu", chinese: 43.0, math: 40, english: 37}
	students[4] = student{name: "chenqi", chinese: 30.0, math: 60, english: 40}
	aves := getStuAve(&students)
	fmt.Println(aves)
	fmt.Println(getSubAve(&students))
	fmt.Println(getBelow(&aves))
}
